package com.tsj.SpringBoot.controller;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@EnableConfigurationProperties({ ServerProperties.class })
@Controller
public class IndexController {
	private final static Logger logger = LoggerFactory.getLogger(IndexController.class);
	@Value("${server.port}")
	private String serverPort ;
	
	@Value("${email.name}")
	private String name ;
	@Value("${spring.rabbitmq.host}")
	private String host ;
	@RequestMapping("/")
	public String index(Model model, HttpServletResponse response,ServerProperties serverProperties) {
		model.addAttribute("name", serverPort);
//		model.addAttribute("host", host);
		logger.info("host="+host);
		logger.info("host="+serverProperties.getPort());
//		这里的return 没有加"/",直接就是"index",加了"/"在linux报错
		return "index";
	}

	
	@RequestMapping("/test")
	public String test(Model model, HttpServletResponse response) {
		model.addAttribute("name", serverPort);
		return "/test";
	}
}
 